<?php
    session_start();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>锤子科技商城密码找回</title>

<style>
body{ background-color:#CFF;}
#tbody{ 
    width:1100px; 
	height: auto; 
	margin:0 auto; 
	padding-top: 10px;
}
#forgot{
	background-color: #FFF;
	width: 600px;
	margin: 100px auto;
	padding-top: 20px;
	padding-bottom: 30px;
	padding-left: 50px;
	}
#forgottitle{
	margin: 0;
	padding: 0;
	}
#forgottitle img{
	width: 50px;
	height: 50px;
	vertical-align: middle;
	}
#forgottitle span{
    display: block;
	}
#fodiv2{
	width: 500px;
	margin: 0 auto;	
	overflow: hidden
	}
#formforgot dt{
	float: left;
	margin:10px;
	width: 60px;
	vertical-align: middle;
	display: inline-block;
	height: 25px;
	 text-align:justify;
     text-align-last:justify;
}
#formforgot dt:after{
     display:inline-block;
     overflow:hidden;
     width:100%;
     height:0;
     content:'';
     vertical-align: middle;
}
#formforgot dd{
	float: left;
	margin:10px;
	width: 400px;
	height: 25px;
	}
#formforgot p{
	margin: 0;
	padding: 0;
	}
#uname{
     width: 250px;
	}
#secode{
     width: 100px;
	}
#sendcode{
     width: 150px;
	 display: block;
	 float: right;
	}
#yanzheng{
     width: 150px;
	}
.error{
	color:red;
}






</style>



<script type="text/javascript" src="../js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="../js/validate-1.14.0.min.js"></script>

<script>

$().ready(function() {

$(function(){
  $('#formforgot').validate({
		rules:{
			uname:{
				required:true,
			/*	email: ture,
				  不验证？？？ 用户名存在
				remote:{
				    url: "checkuserexist.php",
				    type: "post",               
                    dataType: "json",              
                    data: {                    
                        username: function() {
                        return $("#uname").val();
                          }
					}  
				}  */
			},
			secode:{
				required:true,
				rangelength:[6,6]
			}
		},
		messages:{
			uname:{
				required:"请输入一个用户名",
				email: "请输入正确的邮箱",
				remote: "用户名不存在"
			},
			secode:{
				required:'请输入验证码',
				rangelength:'验证码为6位'
			}
		}
	});	
  });


$(function(){ 
$("#sendcode").click(function(){ 
var email = $("#uname").val(); 

 
$("#sendcode").attr("disabled","disabled").val('验证码发送中..').css("cursor","default"); 
$.post("sendmail.php",{mail: email},function(msg){
	
	var n = msg.indexOf("noreg");

if(n >= 0){ 
    $(".error1").html("*该邮箱尚未注册！"); 
    $("#sendcode").removeAttr("disabled").val('点击发送验证码').css("cursor","pointer"); 
    }
  else{ 
    $(".error1").html("*"); 
    $("#sendcode").attr("disabled","disabled").val('请进行验证（10min）').css("cursor","default");
    $("#msgmsg").html(msg); 
    }

}); 
 
});
 
});

});
</script>



</head>

<body>
<?php
include "../mysql/mysql.php";
$aa = new mysql;
$aa->link("");
include "../myfunction.php";
$bb= new myfunction;

if(@$_POST['uname'] != '' && @$_POST['secode'] != ''){
$uname = @$_POST['uname'];
$token = @$_POST['secode'];
//var_dump($uname);var_dump($token);
$res = $bb->finduser($uname);
//var_dump($res);
if($token == $res['token']){
	$_SESSION['userid']=$uname;
	echo "<meta http-equiv=\"refresh\" content=\"0.5;url='reset.php'\">";
	}
	else{
		$err=1;
		}
}


?>
<div id="tbody">

    <div id="forgot">
         <div style=" margin: 0 auto; width: 200px;"><p id="forgottitle"><span><img src="../img/head-logo.jpg" />　<strong>密码找回</strong></span></p></div>
         <div id="fodiv2">
                <form method="post" action="" id="formforgot">
            <dl>
                <dt>用户名</dt><dd><p><input id="uname" name="uname" type="email" placeholder="请输入注册时的邮箱"><span class="error error1">*</span></p></dd>
                <dt>验证码</dt><dd><p><input id="secode" name="secode" type="text" placeholder="六位验证码"><span class="error">*<?php if(@$err == 1) { echo "验证码输入不正确";} ?></span><input id="sendcode" name="sendcode" type="button" value="点击发送验证码"></p></dd> 
            </dl>         
                <div style=" margin: 0 auto; width: 200px;"><input type="submit" name="submit" value="提　　交" id="yanzheng" style='font-size:20px'></div>
            
               </form>
              <div><p style="text-align: center; color: red;"><small><span id="msgmsg"></span></small></p></div>
               
         </div>
    
    </div>









</div>
<?php
include "../mysql/mysqlclose.php";
?>

</body>
</html>